<template>
    <div id="main">
        <div class="bar">
            <div class="left">
                关于我们
            </div>
            <div class="right">
                <el-button type="success" size="mini"  @click="addMenu()"> <i class="el-icon-plus"></i> 添加类目</el-button>
            </div>
        </div>
        <div class="table">
            <el-table
                :data="tableData"
                style="width: 100%;margin-bottom: 20px;"
                row-key="id"
                border
                default-expand-all
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <el-table-column
                prop="id"
                label="ID"
                align="center"
                sortable
               >
                </el-table-column>

                <el-table-column
                prop="fid"
                align="center"
                label="分类"
                sortable
                >
                 <template slot-scope="scope">
                     <div>
                         {{ scope.row.fid | getNav }}
                     </div>
                 </template>
                </el-table-column>

                <el-table-column
                prop="title"
                align="center"
                label="名称"
                sortable
                >
                </el-table-column>

                



                <el-table-column
                prop="content"
                align="center"
                label="简介">
                <template slot-scope="scope">
                    <el-popover trigger="hover" placement="top" style="width:300px;">
                        <p>{{ scope.row.content }}</p>
                        <div slot="reference" class="name-wrapper">
                            <el-tag style="width:100px" size="medium">查看简介</el-tag>
                        </div>
                        </el-popover>
                </template>
                </el-table-column>
                
 
                <el-table-column
                prop="status"
                align="center"
                label="状态">
                    <template slot-scope="scope">
                        <el-button :type="scope.row.status == 1 ? 'success': 'danger' " size="mini" @click="changeStatus(scope.row.id)">{{ scope.row.status == 1 ? "开启" : "关闭" }}</el-button>
                    </template>
                </el-table-column>

                <el-table-column
               
                align="center"
                label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="editMenu(scope.row)">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- dialog -->
        <art-class-dialog :DialogData="DialogData" :FormData="FormData" @update="getAllMember"></art-class-dialog>
    </div>
</template>

<script>
    var self
    import ArtClassDialog from "@/components/dialog/ArtClassDialog"
    export default {
        data() {
            return {
                tableData: [],
                DialogData: {
                    title: "",
                    show: false,
                },
                FormData: {},
                select: [
                    { value:1, label: "关于我们"},
                    { value:2, label: "帮助中心"},
                    { value:3, label: "支付方式"},
                ],
            }
        },
        components: {
            ArtClassDialog,
        },
        beforeCreate() {
            self = this
        },
        filters: {
            getNav: function(value) {
                let str = ""
                self.select.forEach( el => {
                    if (el.value == value) {
                        str = el.label
                    }
                })
                return str
            }
        },
        computed: {
            token() {
                return localStorage.token; 
            }
        },
        mounted() {
            this.getAllMember()
        },
        methods: {
            // 获取所有会员
            async getAllMember() {
                let res = await this.$axios.post("/admin/index/aboutshow", { token: this.token })
                console.log(res);
                if(res.data.code == 200) {
                    this.tableData = res.data.data
                }
                
            },
            // 编辑菜单
            editMenu( user ) {
                this.$router.push(`/adoutuslist/${user.id}`)
            },
            // 添加菜单
            addMenu(id) {
                this.$router.push("/adoutuslist/add")
            },
            // 菜单状态改变
            async changeStatus( id ) {
                let res = await this.$axios.post("", {token: this.token, id })
                // console.log(res);
                if(res.data.code == 204) {
                    this.$message.success("更新成功")
                    this.getAllMenu()
                } else {
                    this.$message.success("更新失败")
                    this.getAllMenu()
                }
                
            },
        },
    }
</script>

<style lang="scss" scoped>
 #main {
     width: 100%;
     box-sizing: border-box;
     .bar {
         width: 100%;
         font-weight: bold;
         display: flex;
         justify-content: space-between;
         height: 40px;
         line-height: 40px;
         border-bottom: 1px solid #aaa;
     }
     .table {
         margin-top: 20px;
     }
     .pic {
         width: 40px;
         height: 40px;
         display: block;
     }
 }
</style>